﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Typing_GUI.CLASS;

namespace Typing_GUI
{
    public partial class frmUser : Form
    {
        public frmUser()
        {
            InitializeComponent();
        }
        #region "BIẾN - ID - UserName"
        public int userID;

        private string m_userName;

        public string UserName
        {
            get { return m_userName; }
            set { m_userName = value; }
        }
        public int flag = 0;
        #endregion
        private void btnAdventure_Click(object sender, EventArgs e)
        {
            frmLevels frm = new frmLevels();
            frm.userID = userID;
            frm.type = 2;
            frm.FormClosed += new FormClosedEventHandler(MakeVisibleAgain);
            frm.Show();
            this.Visible = false;
        }
        private void txtTypingText_Click(object sender, EventArgs e)
        {
            frmLevels frm = new frmLevels();
            frm.userID = userID;
            frm.FormClosed += new FormClosedEventHandler(MakeVisibleAgain);
            frm.Show();
            this.Visible = false;
        }
        private void MakeVisibleAgain(object sender, FormClosedEventArgs e)
        {
            this.Visible = true;
        }

        private void btnManageLesson_Click(object sender, EventArgs e)
        {
            frmManageLesson  frm = new frmManageLesson();
            frm.FormClosed += new FormClosedEventHandler(MakeVisibleAgain);
            frm.userID = userID;
            frm.Show();
            this.Visible = false;
        }

        private void btnTopMembers_Click(object sender, EventArgs e)
        {
            Form frm = new frmTopMembers();
            frm.FormClosed += new FormClosedEventHandler(MakeVisibleAgain);
            frm.Show();
            this.Visible = false;
        }

        private void btnStatistics_Click(object sender, EventArgs e)
        {
           frmStatistics frm = new frmStatistics();
           frm.Id = userID;
            frm.FormClosed += new FormClosedEventHandler(MakeVisibleAgain);
            frm.Show();
            this.Visible = false;
        }

        private void btnInfomation_Click(object sender, EventArgs e)
        {
            frmInformation frm = new frmInformation();
            frm.userID = userID;
            frm.FormClosed += new FormClosedEventHandler(MakeVisibleAgain);
            frm.Show();
            this.Visible = false;
        }

        private void btnQuitGame_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmUser_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (flag == 0)
            {
                if (MessageBox.Show("Do you want to exit game ?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    e.Cancel = true;
                else
                {
                    foreach (Form frm in Application.OpenForms)
                    {
                        if (frm is frmLogin)
                        {
                            ((frmLogin)frm).Close();
                            break;
                        }
                    }
                }
            }
        }

        private void frmUser_Load(object sender, EventArgs e)
        {
           
            try
            {
                string hoTen = CNguoiDung.HoTenNguoiDung(userID);
                
                llblUserName.Text = hoTen;
            }
            catch
            {
                MessageBox.Show("Error connecting database ", "ERROR !!", MessageBoxButtons.OK, MessageBoxIcon.Error); 
            }
            
        }

        private void btExam_Click(object sender, EventArgs e)
        {
            frmExamList frm = new frmExamList();
            frm.userID = userID;
            frm.FormClosed += new FormClosedEventHandler(MakeVisibleAgain);
            frm.Show();
            this.Visible = false;
        }

    

        private void llblUserName_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            frmInformation frm = new frmInformation();
            frm.userID = userID;
            frm.FormClosed += new FormClosedEventHandler(MakeVisibleAgain);
            frm.Show();
            this.Visible = false;
        }

        private void llblLogout_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            flag = 1;

            this.Close();
            foreach (Form frm in Application.OpenForms)
            {
                if (frm is frmLogin)
                {
                    ((frmLogin)frm).Controls[5].Focus();
                    break;
                }
            }
        }
    }
}